|
|
 |
|
|
|
|
y2 = Int(FromYmin + _
(iy_out + 1 - ToYmin) / YScale) - 1
' Average the pixels in this area. r = 0
g = 0
b = 0
For X = x1 To x2
For Y = y1 To y2
With input_pixels(X, Y)
r = r + .rgbRed
g = g + .rgbGreen
b = b + .rgbBlue
End With
Next Y
Next X
' Save the result. num_pixels = (x2 - x1 + 1) * (y2 - y1 + 1)
With result_pixels(ix_out, iy_out)
.rgbRed = r / num_pixels
.rgbGreen = g / num_pixels
.rgbBlue = b / num_pixels
End With
Next ix_out
Next iy_out |
|
|
|
|
|
|
|
|
Compare program Reduce's output with the output of program Shrink shown in Figure 7.15. Program Reduce gives a much smoother result, though it takes longer. Program Reduce also gives equal weight to all of the input pixel values. Your image might contain small areas that are important to the structure of the picture. In Figure 7.16, for example, the thin, dark lines are important to the image while the gray background is not. By averaging all of the pixel values, the program dilutes the important data with the background data. This makes the dark, thin lines lighter, and the image appears more blurred. |
|
|
|
|
|
|
|
|
If you know you are working with this sort of image, you can reduce this effect by unsharp masking or high-pass filtering to sharpen the result. |
|
|
|
|
|
|
|
|
Example program Resize uses the techniques describe in this and the previous section to enlarge or reduce an image. The ResizePicture subroutine examines its parameters to determine whether it is enlarging or shrinking an image. It then calls the appropriate routine to transform the image. |
|
|
|
|
|
|
|
|
The LoadImage API function loads icons, cursors, and bitmaps. You can use it to load an image from a file with anti-aliasing. This routine does not produce quite as nice a result as the routines described in the previous sections, particularly when you are shrinking an image, but it is much faster. In one test on a 133MHz Pentium, program Resize took 4.28 seconds to enlarge an image while the LoadImage function took only 0.37 seconds. |
|
|
|
|
|